<template>
  <div class="app-container home">
      <!-- 主内容区 -->
      <main class="main-content container">
        <!-- 快捷导航和系统简介 -->
        <div class="content-grid">
          <!-- 快捷导航 -->
          <div class="card shortcut-nav">
            <h2 class="card-title">快捷导航</h2>
            <div class="nav-grid">
              <div
                v-for="(item, index) in navItems"
                :key="index"
                class="nav-item"
                :style="{ backgroundColor: item.color }"
                @click="handleNavClick(item.path)"
              >
                <i :class="['fa', item.icon]"></i>
                <span class="nav-text">{{ item.name }}</span>
                <span v-if="item.badge" class="badge" :style="{ backgroundColor: item.badgeColor }">
                {{ item.badge }}
              </span>
              </div>
            </div>
          </div>

          <!-- 系统简介 -->
          <div class="card system-intro">
            <h2 class="card-title">{{ systemInfo.title }}</h2>
            <div class="intro-content">
              <div class="intro-section">
                <h3 class="section-title">平台简介</h3>
                <p class="section-text">{{ systemInfo.description }}</p>
              </div>
              <div class="intro-section">
                <h3 class="section-title">功能描述</h3>
                <p class="section-text">{{ systemInfo.features }}</p>
              </div>
              <div class="intro-section">
                <h3 class="section-title">当前版本：{{ systemInfo.version }}</h3>
                <button class="official-site-btn">公司官网</button>
              </div>
            </div>
          </div>
        </div>

        <!-- 图表区域 -->
        <div class="content-grid">
          <!-- 柱状图 -->
          <div class="card chart-card">
            <h2 class="card-title">数据统计（柱状图）</h2>
            <div class="chart-container">
              <div ref="barChart" class="chart"></div>
            </div>
          </div>

          <!-- 饼图 -->
          <div class="card chart-card">
            <h2 class="card-title">数据统计（饼图）</h2>
            <div class="chart-container">
              <div ref="pieChart" class="chart"></div>
            </div>
          </div>
        </div>
      </main>

      <!-- 页脚 -->
      <footer class="footer">
        <div class="container">
          <p>© 2023 工程项目管理系统 V2.0.1 - 版权所有</p>
        </div>
      </footer>
  </div>
</template>

<script>
import * as echarts from 'echarts';
export default {
  name: 'ProjectManagementSystem',
  data() {
    return {
      // 导航项数据
      navItems: [
        { name: '待办任务', path: 'task/todo', icon: 'fa-briefcase', color: '#ff7d00', badge: 6, badgeColor: '#fbbf24' },
        { name: '已办任务', path: 'task/finished', icon: 'fa-briefcase', color: '#00b5ad', badge: 5, badgeColor: '#3b82f6' },
        { name: '资金管理', path: 'money/moneyManager', icon: 'fa-file-text-o', color: '#ff6b9b' },
        { name: '流程管理', path: 'flowable/definition', icon: 'fa-file-text-o', color: '#6b84ff'},
        { name: '投标信息', path: 'manager/bid/bid', icon: 'fa-paper-plane', color: '#21ba45' },
        { name: '合同管理', path: 'kobe/contract/project', icon: 'fa-file-text', color: '#00bcd4' },
        { name: '财务管理', path: 'money/orderManager', icon: 'fa-file-text-o', color: '#00bcd4' },
        { name: '物资管理', path: 'kobe/asset/info', icon: 'fa-desktop', color: '#00b5ad' }
      ],

      // 系统信息
      systemInfo: {
        title: '牢大工程管理系统v2.0.1',
        description: '工程项目管理系统是一款专为工程项目公司打造的综合性OA办公系统，旨在满足工程项目进度及成本控制管理，助力企业高效办公，全方位整合信息技术与项目管理理念。本项目二次开发，该系统分为管理端和小程序端两部分。',
        features: '系统功能包括立项管理、项目预算、投标管理、合同管理、施工进度、验收管理、财务管理、物资管理、文件管理、任务提醒等。',
        version: 'v2.0.1'
      },

      // 图表实例
      barChart: null,
      pieChart: null
    }
  },
  methods: {
    // 导航点击事件
    handleNavClick(path) {
      // 实际项目中可替换为路由跳转
      this.$router.push({ path: path })
    },

    // 初始化柱状图
    initBarChart() {
      this.barChart = echarts.init(this.$refs.barChart)
      this.barChart.setOption({
        tooltip: { trigger: 'axis', stacked: true },
        xAxis: {
          type: 'category',
          data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月']
        },
        yAxis: { type: 'value', max: 1200 },
        series: [
          {
            name: '项目数量',
            type: 'bar',
            stack: '总量',
            data: [100, 80, 200, 300, 380, 320, 200],
            itemStyle: { color: '#00b5ad' }
          },
          {
            name: '完成项目',
            type: 'bar',
            stack: '总量',
            data: [80, 60, 180, 350, 380, 340, 220],
            itemStyle: { color: '#9370db' }
          },
          {
            name: '新增项目',
            type: 'bar',
            stack: '总量',
            data: [20, 20, 120, 350, 400, 340, 220],
            itemStyle: { color: '#2185d0' }
          }
        ]
      })
    },

    // 初始化饼图
    initPieChart() {
      this.pieChart = echarts.init(this.$refs.pieChart)
      this.pieChart.setOption({
        tooltip: { trigger: 'item' },
        legend: {
          orient: 'vertical',
          left: 'left',
          data: ['建筑工程', '市政工程', '装饰工程', '安装工程', '其他工程']
        },
        series: [
          {
            name: '项目类型分布',
            type: 'pie',
            radius: '50%',
            data: [
              { value: 40, name: '建筑工程' },
              { value: 30, name: '市政工程' },
              { value: 15, name: '装饰工程' },
              { value: 8, name: '安装工程' },
              { value: 7, name: '其他工程' }
            ],
            itemStyle: {
              colors: ['#00b5ad', '#9370db', '#2185d0', '#f5a623', '#e53e3e']
            }
          }
        ]
      })
    },

    // 处理窗口 resize
    handleResize() {
      if (this.barChart) this.barChart.resize()
      if (this.pieChart) this.pieChart.resize()
    }
  },
  mounted() {
    // 初始化图表
    this.initBarChart()
    this.initPieChart()

    // 监听窗口大小变化
    window.addEventListener('resize', this.handleResize)
  },
  beforeDestroy() {
    // 销毁图表实例，释放资源
    if (this.barChart) this.barChart.dispose()
    if (this.pieChart) this.pieChart.dispose()

    // 移除事件监听
    window.removeEventListener('resize', this.handleResize)
  }
}
</script>

<style scoped lang="scss">
.project-management {
  min-height: 100vh;
  background-color: #f3f4f6;
  font-family: 'Inter', system-ui, sans-serif;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}

// 头部样式
.header {
  background-color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  padding: 16px 0;

  .logo {
    display: flex;
    align-items: center;
    gap: 8px;

    i {
      color: #2185d0;
      font-size: 24px;
    }

    h1 {
      font-size: 18px;
      font-weight: 600;
      color: #1f2937;
      margin: 0;
    }
  }

  .user-info {
    display: flex;
    align-items: center;
    gap: 20px;
  }

  .notification-btn {
    background: none;
    border: none;
    color: #4b5563;
    cursor: pointer;
    font-size: 20px;
    transition: color 0.2s;

    &:hover {
      color: #2185d0;
    }
  }

  .user {
    display: flex;
    align-items: center;
    gap: 8px;

    .avatar {
      width: 32px;
      height: 32px;
      border-radius: 50%;
      object-fit: cover;
    }

    .username {
      font-size: 14px;
      color: #4b5563;
    }
  }
}

// 主内容区样式
.main-content {
  padding: 32px 0;
}

.content-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  margin-bottom: 24px;

  @media (min-width: 1024px) {
    grid-template-columns: repeat(2, 1fr);
  }
}

.card {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  padding: 20px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
  margin: 0 0 16px 0;
}

// 快捷导航样式
.shortcut-nav {
  .nav-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;

    @media (min-width: 640px) {
      grid-template-columns: repeat(3, 1fr);
    }

    @media (min-width: 768px) {
      grid-template-columns: repeat(6, 1fr);
    }
  }

  .nav-item {
    border-radius: 6px;
    padding: 16px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #fff;
    cursor: pointer;
    position: relative;
    transition: transform 0.2s;

    &:hover {
      transform: scale(1.05);
    }

    i {
      font-size: 24px;
      margin-bottom: 8px;
    }

    .nav-text {
      font-size: 12px;
      text-align: center;
    }

    .badge {
      position: absolute;
      top: 4px;
      right: 4px;
      width: 20px;
      height: 20px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 10px;
      font-weight: 600;
    }
  }
}

// 系统简介样式
.system-intro {
  .intro-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
  }

  .intro-section {
    .section-title {
      font-size: 14px;
      font-weight: 600;
      color: #1f2937;
      margin: 0 0 8px 0;
    }

    .section-text {
      font-size: 13px;
      color: #6b7280;
      line-height: 1.6;
      margin: 0;
    }
  }

  .official-site-btn {
    background-color: #fee2e2;
    color: #dc2626;
    border: none;
    border-radius: 4px;
    padding: 4px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.2s;

    &:hover {
      background-color: #fecaca;
    }
  }
}

// 图表样式
.chart-card {
  .chart-container {
    width: 100%;
    height: 320px;
    background-color: #f9fafb;
    border-radius: 6px;
  }

  .chart {
    width: 100%;
    height: 100%;
  }
}

// 页脚样式
.footer {
  background-color: #fff;
  border-top: 1px solid #e5e7eb;
  padding: 20px 0;
  margin-top: 40px;

  p {
    font-size: 12px;
    color: #6b7280;
    text-align: center;
    margin: 0;
  }
}
</style>

